package com.xrit.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.constant.MessageConstant;
import com.xrit.exception.CustomException;
import com.xrit.pojo.CheckGroup;
import com.xrit.query.QueryPageBean;
import com.xrit.result.PageResult;
import com.xrit.result.Result;
import com.xrit.service.CheckGroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checkGroup")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    /**
     * 查询所有
     */
    @RequestMapping("/findAll.do")
    public Result findAll(){
        //System.out.println("检查组列表。。。。。");
        List<CheckGroup> all = checkGroupService.findAll();
        return new Result(true, all==null? MessageConstant.QUERY_CHECKGROUP_FAIL: MessageConstant.QUERY_CHECKGROUP_SUCCESS,all);
    }


    @RequestMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup,Integer [] checkitemIds){
        checkGroupService.add(checkGroup,checkitemIds);
        return new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    //删除
    @PostMapping("/deleteById")
    public Result deleteById(Integer id) throws CustomException {
        checkGroupService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }

    /**
     * 分页条件查询
     */
    @RequestMapping("/findPage.do")
    public Result findAll(@RequestBody QueryPageBean queryPageBean){
        //System.out.println("检查组列表。。。。。");
        PageResult all = checkGroupService.findPage(queryPageBean);
        return new Result(true, all==null? MessageConstant.QUERY_CHECKGROUP_FAIL:MessageConstant.QUERY_CHECKGROUP_SUCCESS,all);
    }
}
